package com.nbjtjc.safe.service.edu;

import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.edu.EduEntryTrainingDepartmentMapper;
import com.nbjtjc.safe.model.edu.EduEntryTrainingDepartment;

@Service
public class EduEntryTrainingDepartmentService {
	@Autowired
	EduEntryTrainingDepartmentMapper eduEntryTrainingDepartmentMapper;
	
	  public Result add(EduEntryTrainingDepartment eduEntryTrainingDepartment){
	        Result result=new Result();
	        if(ObjectUtil.isNull(eduEntryTrainingDepartment)
	        		||ObjectUtil.isNull(eduEntryTrainingDepartment.getTrainingId())
	        		){
	            result.setFalse("部门培训ID不能为空");
	            return result;
	        }

	        if(ObjectUtil.isNull(eduEntryTrainingDepartment.getId())
	        		|| ObjectUtil.isNull(eduEntryTrainingDepartmentMapper.selectByPrimaryKey(eduEntryTrainingDepartment.getId()))){
	        	
	        	int res=eduEntryTrainingDepartmentMapper.insertSelective(eduEntryTrainingDepartment);
		            
		        if(res==0){
		            result.setFalse("插入失败");
		            return result;
	
		        }
		        }else
		        {
		        	int res=eduEntryTrainingDepartmentMapper.updateByPrimaryKeySelective(eduEntryTrainingDepartment);
		        	 if(res==0){
		        		 result.setFalse("更新失败");
				         return result;
	
		        	 }
		        }
	        result.setData(eduEntryTrainingDepartment);
	        return result;
	    }



	public Result delete(int id){
	    Result result=new Result();
	    if(ObjectUtil.isNull(id)){
	        result.setFalse("删除对象不能为空");
	        return result;
	    }
	    int res=eduEntryTrainingDepartmentMapper.deleteByPrimaryKey(id);
	    if(res==0){
	        result.setFalse("删除失败");
	        return result;
	        }
	    return result;
	}
	
	//根据条件查找调查项目
	
	public Result find(EduEntryTrainingDepartment eduEntryTrainingDepartment) {
	    Result result = new Result();
	    PageHelper.startPage(eduEntryTrainingDepartment.getPageCurrent(), eduEntryTrainingDepartment.getPageSize());

	    List<EduEntryTrainingDepartment> eduEntryTrainingDepartments = eduEntryTrainingDepartmentMapper.select(eduEntryTrainingDepartment);
	    result.setData(new PageInfo<>(eduEntryTrainingDepartments));
	
	    return result;
	}
}
